﻿
namespace FlyingHat.Common.Helper
{
    /// <summary>
    /// 此项存在问题仅加载系统内置的依赖服务，未能加载Autofac的服务
    /// </summary>
    public static class ServicesHelper
    {
        /// <summary>
        /// ServiceProvider
        /// </summary>
        public static IServiceProvider? ServiceProvider { get; set; }

        /// <summary>
        /// 获取服务(请求生命周期内)
        /// </summary>
        /// <typeparam name="T">接口类型</typeparam>
        /// <returns></returns>
        public static T? GetScopeService<T>() where T : class
        {
            if (ServiceProvider == null)
            {
                return null;
            }
            var service = ServiceProvider.GetService(typeof(T));
            return service as T;

        }
    }
}
